package com.vhall.component.entity.paas;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * PAAS聊天消息列表响应
 *
 * @author yuanzh
 */
@Data
@NoArgsConstructor
public class PaasMessageListRspDTO implements Serializable {

    private static final long serialVersionUID = -5955924976084316713L;

    /**
     * required 消息总条数
     */
    private Integer total;

    /**
     * required 当前页
     */
    @JSONField(name = "page_num")
    private Integer current;

    /**
     * required 总页数
     */
    @JSONField(name = "page_all")
    private Integer totalPage;

    /**
     * required 消息列表
     */
    private List<PaasChatRecord> list;

    /**
     * 获取所有用户id
     *
     * @return 用户ids
     */
    @JSONField(serialize = false)
    public Set<String> getAllUserId() {
        return this.list.stream().map(PaasChatRecord::getThirdPartyUserId).collect(Collectors.toSet());
    }

    @Data
    public static class PaasChatRecord {

        /**
         * 消息ID
         */
        @JSONField(name = "msg_id")
        private String msgId;

        /**
         * 消息类型
         */
        private String type;

        /**
         * 用户消息数据
         */
        private String data;

        /**
         * 发送消息时间戳
         */
        @JSONField(name = "date_time")
        private String dateTime;

        /**
         * 消息发送者的第三方用户ID
         */
        @JSONField(name = "third_party_user_id")
        private String thirdPartyUserId;

        /**
         * 昵称
         */
        @JSONField(name = "nick_name")
        private String nickname;

        /**
         * 头像
         */
        private String avatar;

        /**
         * 用户自定义消息体
         */
        private JSONObject context;

        @JSONField(name = "image_urls")
        private JSONArray imageUrls;

    }
}
